Skip to content

Add HashingUtils addToHash(Object[]) overloads - #12043

Open
dougqh wants to merge 2 commits into
masterfrom
dougqh/hashing-utils-array-helpers
Open

Add HashingUtils addToHash(Object[]) overloads#12043
dougqh wants to merge 2 commits into
masterfrom
dougqh/hashing-utils-array-helpers

Conversation

@dougqh

@dougqh dougqh commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What Does This Do?

Adds two array-folding helpers to HashingUtils, mirroring overloads that already exist on LongHashingUtils:

  • addToHash(int hash, Object[] arr) — folds every element onto the running hash.
  • addToHash(int hash, Object[] arr, int len) — folds only the first len elements.

It also annotates the nullness contract of the addToHash overloads (and their null-folding delegates) across both HashingUtils and LongHashingUtils: the single-Object overloads are @Nullable, and the Object[] overloads are @Nonnull (the array must be non-null; its elements may still be null).

Motivation

Similar conveniences proved useful on LongHashingUtils while working on client-side-stats, so they make sense for (Integer) HashingUtils, too. Restores parity with LongHashingUtils, which already carries the equivalent methods.

The @Nullable/@Nonnull pass documents why a bare addToHash(seed, null) literal binds to the Object[] overload rather than the single-Object one — turning a would-be silent overload-resolution surprise into a declared contract, kept symmetric across the int and long families (per Codex review feedback).

Additional Notes

Unit tests cover the full-array fold (equivalence with hash(Object[])), non-zero-seed carry-through, partial-len folding, and len == 0 (loop not entered), so both loop-branch outcomes are exercised.

🤖 Generated with Claude Code

@dougqh dougqh added comp: core Tracer core tag: no release notes Changes to exclude from release notes type: refactoring tag: ai generated Largely based on code generated by an AI or LLM labels Jul 22, 2026
@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 57.24% (-0.46%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 405bfd2 | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.98 s 13.98 s [-0.8%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 12.95 s 12.91 s [-0.5%; +1.0%] (no difference)
startup:petclinic:appsec:Agent 17.05 s 16.97 s [-0.4%; +1.4%] (no difference)
startup:petclinic:iast:Agent 16.96 s 17.03 s [-1.3%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 16.99 s 16.77 s [+0.0%; +2.6%] (maybe worse)
startup:petclinic:sca:Agent 16.96 s 16.93 s [-0.6%; +1.1%] (no difference)
startup:petclinic:tracing:Agent 15.67 s 16.14 s [-7.2%; +1.3%] (no difference)

Commit: 405bfd2b · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@dougqh

dougqh commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 756cd02874

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal-api/src/main/java/datadog/trace/util/HashingUtils.java
@dougqh
dougqh marked this pull request as ready for review July 28, 2026 19:57
@dougqh
dougqh requested a review from a team as a code owner July 28, 2026 19:57
@dougqh
dougqh requested a review from mcculls July 28, 2026 19:57
@dd-octo-sts

dd-octo-sts Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Remove the tag from the pull request title

If you need help, please check our contributing guidelines.

@datadog-prod-us1-5 datadog-prod-us1-5 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: FAIL

The new Object[] overload changes the meaning of an existing call with a null literal: addToHash(0, null) now selects the array overload and throws NullPointerException instead of returning the unchanged seed. Array folding behavior is otherwise correct for mixed values, null elements, empty arrays, and bounded prefixes.

📊 Validated against 5 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit 756cd02 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

return hash;
}

public static final int addToHash(int hash, Object[] arr) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Null literal now throws through the array overload

Existing callers using a null literal can fail at runtime after recompiling against this version, instead of preserving the prior null-hashing behavior.

Assertion details
  • Input: A caller invokes the pre-existing API as HashingUtils.addToHash(0, null).
  • Expected: The existing Object overload is selected and hashCode(null) contributes zero, returning the seed unchanged.
  • Actual: The new Object[] overload is more specific for the null literal, so it calls arr.length and throws NullPointerException.

Was this helpful? React 👍 or 👎
🤖 Datadog Autotest · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

dougqh and others added 2 commits July 28, 2026 16:43
Mirror the array-folding helpers already present on LongHashingUtils:
addToHash(hash, Object[]) and addToHash(hash, Object[], len), the latter
folding only the first len elements. Split out of the client-side stats
branch, where they were added but unused.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Make the split-key contract explicit with javax.annotation:
- addToHash(int/long, Object) and its null-folding delegate
  (hashCode/intHash) take @nullable — null hashes to a stable value.
- addToHash(int/long, Object[], int) and the length-defaulting
  overload take @nonnull — a null array is a caller error, while
  individual elements may still be null (noted in Javadoc).

This documents why a bare `addToHash(seed, null)` literal now binds to
the Object[] overload rather than the single-Object one, and keeps the
int and long hashing families symmetric.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/hashing-utils-array-helpers branch from 756cd02 to 405bfd2 Compare July 28, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants